package com.example.secondhandspringboot.controller;


import com.example.secondhandspringboot.domain.entity.Category;
import com.example.secondhandspringboot.results.Result;
import com.example.secondhandspringboot.service.ICategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周在林
 * @since 2024-04-02
 */
@RestController
@RequestMapping("/category")
@CrossOrigin
@RequiredArgsConstructor
@Slf4j
public class CategoryController {

    private final ICategoryService categoryService;

    /**
     * 获取分类
     * @return
     */
    @GetMapping("/getCategory")
    @Cacheable(cacheNames = "categoryCache")
    public Result<List<Category>> getCategory(){
        log.info("获取分类");
        List<Category> categoryList = categoryService.list();
        return Result.success(categoryList);
    }
}
